
#include <stdio.h>
#include <unistd.h>
#include <linux/getprocinfo.h>
#include "print_task.h"
#include <sys/types.h>
#include <sys/wait.h>

int main() {


  printf("\nThis program will use a lot of system time.");
  printf("\nIt calls fork() repeatedly in a loop, and then");
  printf("\nprints its task_info_struct information.\n\n");

  printf("\nMy Pid is:  %ld ", (long)getpid() );

  printf("\n\nForking . . .\n");
  int i;
  for (i = 0; i < 100000; i++) {

    int pid = fork() ;
    if ( pid ) {
      waitpid( pid, NULL, 0 );
    }
    else {
      exit( 0 );
    }

  }
 
  printf("\nHere is my task_info_struct information: ");
  struct proc_info_struct s;
  getprocinfo( 0, &s );

  print_task( &s );
   

  printf("\nExiting.\n");
  return 0;
  

}
